package com.guijq.codesegment.tree;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author yangjf
 * @version 0.1.0
 * @time 2018/8/13/013
 */
@Getter
@AllArgsConstructor
public enum TreeNodeLevelEnum {

    FIRST(1, "第一层"), //是否型（仅需录入合格数量）
    SECOND(2, "第二层"), //选项型（需录入检验项目的选择项）
    THIRD(3, "第三层"); //输入型（需录入检验项目精确值）


    private int code;
    private String message;

    public static TreeNodeLevelEnum getEnum(int index) {
        for (TreeNodeLevelEnum c : TreeNodeLevelEnum.values()) {
            if (c.getCode() == index) {
                return c;
            }
        }
        throw new RuntimeException();
    }

    public static boolean existNextLevel(int code) {
        for (TreeNodeLevelEnum c : TreeNodeLevelEnum.values()) {
            if (c.getCode() == code + 1) {
                return true;
            }
        }
        return false;
    }

    public static boolean existPreviousLevel(int code) {
        for (TreeNodeLevelEnum c : TreeNodeLevelEnum.values()) {
            if (c.getCode() == code - 1) {
                return true;
            }
        }
        return false;
    }


    public static TreeNodeLevelEnum getNextLevel(int id) {
        return getEnum(id + 1);
    }

    public static TreeNodeLevelEnum getPreviousLevel(int id) {
        return getEnum(id - 1);
    }



}
